package com.example.androidproject.activity.utils

import android.app.Activity
import android.graphics.Color
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat

/**
 * isFit false  打开沉浸式
 */
fun Activity.showFitsSystemWindow(isFit:Boolean = true){
    WindowCompat.setDecorFitsSystemWindows(window,isFit)
}

/**
 * 显示状态栏,字体黑色
 */
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
fun Activity.showDarkStatusBar(){
    window.statusBarColor = Color.TRANSPARENT //设置底色
    ViewCompat.getWindowInsetsController(window.decorView)?.let { controller ->
        controller.show(WindowInsetsCompat.Type.statusBars())
        controller.isAppearanceLightStatusBars = true//true字体黑色,false白色
    }

}
/**
 * 显示导航栏
 */
fun Activity.showNavigation(show:Boolean){
    if (show){
        ViewCompat.getWindowInsetsController(window.decorView)?.let { controller ->
            controller.show(WindowInsetsCompat.Type.navigationBars())
            controller.isAppearanceLightNavigationBars = true//true icon黑色,false白色
        }
    }else{
        ViewCompat.getWindowInsetsController(window.decorView)?.hide(WindowInsetsCompat.Type.navigationBars())
    }
}
/**
 * 显示软键盘
 */
fun Activity.showKeyBoard(isShow:Boolean){
    if (isShow){
        ViewCompat.getWindowInsetsController(window.decorView)
            ?.show(WindowInsetsCompat.Type.ime())
    }else{
        ViewCompat.getWindowInsetsController(window.decorView)
            ?.hide(WindowInsetsCompat.Type.ime())
    }
}

